#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
int n, u, v; vector < int > g[100009]; priority_queue < pair < int, bool > > f[100009];
inline void dfs(int u, int fa = 0)
{
	for ( int i : g[u] ) if ( i != fa )
	{
		dfs(i, u);
		if ( (int)f[u].size() < (int)f[i].size() ) swap(f[u], f[i]);
		while ( f[i].size() ) f[u].emplace(f[i].top()), f[i].pop();
	}
	if ( f[u].empty() ) { f[u].emplace(1, false); return; }
	auto x = f[u].top(); f[u].pop();
	if ( f[u].empty() ) { f[u].emplace(x.first + ( x.second ? 2 : 0 ), !x.second); return; }
	auto y = f[u].top(); f[u].pop();
	f[u].emplace(x.first + y.first + 1, x.second || y.second);
	if ( x.second && y.second ) f[u].emplace(1, 0);
}
int main()
{
	freopen("bird.in", "r", stdin), freopen("bird.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	cin >> n;
	For(i, 2, n) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
	dfs(1); auto ans = f[1].top(); return cout << ans.first + ans.second << '\n', 0;
}